<?php
/**
 * 首页
 *
 * @copyright  Copyright (c) 2015-2025 NcPHP Inc. (http://www.ncphp.com)
 * @license    http://www.ncphp.com/
 * @link       http://www.ncphp.com/
 * @author     NcPHP Team
 * @since      File available since Release v1.1
 */
defined('InNcPHP') or exit('Access Invalid!');

class indexControl extends BaseHomeControl{

    public function __construct(){
        parent::__construct();
    }

    /**
     * 主页
     */
    public function indexOp(){
        /* @var advertModel $advert_model */
        /*$advert_model = Model('advert');
        $adverts = $advert_model->getAdvertList(array('state'=>1), '*', 'advert_sort asc,advert_id asc');
        foreach ($adverts as $k => $adv) {
            $adverts[$k]['advert_image'] = UPLOAD . 'product/' . $adv['advert_image'];
        }
        Tpl::output('adverts', $adverts);*/
        /* @var ticket_categoryModel $cate_model */
        $cate_model = Model('ticket_category');
        $cates = $cate_model->getCategoryList(array('is_del'=>0,'tc_pid'=>array('gt','0')));
        $cates_all = array();
        foreach ($cates as $k => $cate) {
            if($cate['tc_pid']==1){
                //酒店
                $cates_all['hotel'][] = $cate;
            }elseif($cate['tc_pid']==2){
                //景区
                $cates_all['ticket'][] = $cate;
            }elseif($cate['tc_pid']==3){
                //美食
                $cates_all['food'][] = $cate;
            }elseif($cate['tc_pid']==4){
                //旅行社
                $cates_all['itinerary'][] = $cate;
            }
        }
        //获取资讯频道
        $news_cate = $this->httpGet(CATE_URL);
        $news_cate = object_array(json_decode($news_cate));
        if($news_cate['code']==2000){
            Tpl::output('news_cate',$news_cate['data']['category_list']);
        }
        //获取首页轮播图
        $imgs = $this->httpGet(NEWS_IMG_URL);
        $imgs = object_array(json_decode($imgs));
        if($imgs['code'] == 2000){
            Tpl::output('ads_list',$imgs['data']['hdp']);
        }
        //var_dump($cates_all);exit;
        Tpl::output('cates', $cates_all);
        Tpl::output('city', $_SESSION['pos']['city_name']);

        //Tpl::showpage('index');
        Tpl::setLayout('new_layout');
        Tpl::showpage('index1');
    }


    /**
     * 搜索列表
     */
    public function searchOp() {
        /* @var ticketModel $ticket_model */
        $ticket_model = Model('ticket');

        $fields = implode(',',array(
            'tk_id',
            'tk_title',
            'tk_type',
            'tk_cate1',
            'tk_cate2',
            'tk_city_name',
            'tk_subtitle',
            'tk_thumb',
            'tk_show_price',
            'tk_market_price',
            'tk_city_id',
            'tk_status',
        ));

        $condition = array(/*'tk_city_id'=>$_SESSION['pos']['city_id'],*/ 'tk_status'=>1);
        if ($type = $_GET['type']) {
            $condition['tk_cate1'] = $type;
        }
        if ($title = trim($_GET['title'])) {
            $condition['tk_title'] = array('like','%'.$title.'%');
        }
        if (isset($_GET['recommend'])) {
            $condition['tk_is_recommend'] = 1;
        }
        if (isset($_GET['more'])) {
            $condition['tk_cate1'] = array('in','1,3,4');
        }

        $tickets = $ticket_model->getTicketListPage($condition, $fields, 5);
        foreach ($tickets as $k=>$ticket) {
            $tickets[$k]['tk_thumb'] = UPLOAD.'product/'.$ticket['tk_thumb'];
        }
        Tpl::output('tickets', $tickets);

        //AJAX加载分页
        if (isset($_GET['isajax']) && $_GET['isajax'] == 1) {
            Tpl::showpage('index.search.page', 'null_layout');
            exit;
        }

        Tpl::output('search', $_GET);
        Tpl::output('is_weixin',$this->is_weixin());
        Tpl::output('TotalNum', pagecmd("gettotalnum"));
        Tpl::output('TotalPage', pagecmd("gettotalpage"));
        Tpl::showpage('index.search');
    }

    //检查用户是否登陆
    function _chekloginOp()
    {
        $stuas = $_POST['cheklogin'];
        if($stuas==1){
            if($_SESSION['member']['member_id']>0){
                echo json_encode(array('code'=>200,'msg'=>'已登陆'));
                exit;
            }else{
                echo json_encode(array('code'=>400,'msg'=>'未登陆'));
                exit;
            }

        }
    }


}
